//
//  HomeTopView.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/7/4.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "HomeTopLoginView.h"
#import "HomeViewController.h"

@interface HomeTopLoginView ()


@property (nonatomic, weak)UIImageView * logoImage;

@property (nonatomic, weak)UILabel * mongeyLabel;

//@property (nonatomic, weak)UIImageView * topUpImage;



@end

@implementation HomeTopLoginView


- (instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        
        self.userInteractionEnabled = YES;
        [self setupUI];
    }
    
    return self;
}


- (void)setChangeImageString:(NSString *)changeImageString{
    
    _changeImageString = changeImageString;
    
    if ([self.changeImageString isEqualToString:@"全平"]) {
        
        [self.showRuleButton setTitle:@"查看详情" forState:UIControlStateNormal];
//        self.explationLabel.hidden = NO;
        self.rightImageButton.tag = 2;
    }else{
        
        [self.showRuleButton setTitle:@"点击查看交易规则" forState:UIControlStateNormal];
//        self.explationLabel.hidden = NO;
        self.rightImageButton.tag = 1;
    }
}


- (void)setTraderMoneyString:(NSString *)traderMoneyString{
    
    _traderMoneyString = traderMoneyString;
    
    self.mongeyLabel.text = [NSString stringWithFormat:@"$%@",traderMoneyString];
}


- (void)setupUI{
    
    UIImageView * logoImage = [[UIImageView alloc] init];
    
    logoImage.backgroundColor = [UIColor whiteColor];
    
    self.logoImage = logoImage;
    
    [self addSubview:self.logoImage];
    
    
    UIButton * showRuleButton = [[UIButton alloc] init];
    
    showRuleButton.backgroundColor = [UIColor clearColor];
    
    
    [showRuleButton setTitle:@"点击查看交易规则" forState:UIControlStateNormal];
    
    showRuleButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:10 * SCREENH6];
    [showRuleButton setTitleColor:ColorWithRGB(0xededed) forState:UIControlStateNormal];

    [showRuleButton addTarget:[HomeViewController new] action:@selector(didShowRulesButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.showRuleButton = showRuleButton;
    
    [self addSubview:self.showRuleButton];
    
    
    UILabel * mongeyLabel = [UILabel new];
    
    mongeyLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:24 * SCREENH6];
    mongeyLabel.textColor = ColorWithRGB(0xfd4f4f);
//    mongeyLabel.text = @"$800,000";
    
    self.mongeyLabel = mongeyLabel;
    
    [self addSubview:self.mongeyLabel];
    
    
    UILabel * explationLabel = [UILabel new];
    
    explationLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:11 * SCREENH6];
    explationLabel.textColor = ColorWithRGB(0x898888);
    explationLabel.text = @"交易账户可用资金";
        
    explationLabel.hidden = NO;
    
    self.explationLabel = explationLabel;
    
    [self addSubview:self.explationLabel];
    
    
    UIButton * rightImageButton = [[UIButton alloc] init];
        
    [rightImageButton setImage:[UIImage imageNamed:@"入金"] forState:UIControlStateNormal];
    
    [rightImageButton addTarget:self action:@selector(didRightImageButton:) forControlEvents:UIControlEventTouchUpInside];
    rightImageButton.tag = 1;
    self.rightImageButton = rightImageButton;
    
    [self addSubview:self.rightImageButton];
}



- (void)layoutSubviews{
    
    [self.logoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(75 * SCREENH6);
        make.leading.mas_equalTo(self).offset(25 * SCREENH6);
        make.top.mas_equalTo(10 * SCREENH6);
    }];
    
    [self.showRuleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self.logoImage);
    }];
    
    [self.mongeyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.showRuleButton.mas_bottom).offset(-5 * SCREENH6);
        make.centerX.mas_equalTo(self);
    }];
    
    [self.explationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mongeyLabel.mas_bottom);
        make.centerX.mas_equalTo(self);
    }];
    
    [self.rightImageButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self).offset(-20 * SCREENH6);
        make.top.mas_equalTo(self.logoImage);
        make.width.height.mas_equalTo(75 * SCREENH6);
    }];
}


- (void)didRightImageButton:(UIButton *)button{
    
    NSString * buttonTag = [NSString stringWithFormat:@"%ld",(long)button.tag];
    
    NSDictionary * dict = @{@"buttonTag":buttonTag};
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"didImageButton" object:@"buttonTag" userInfo:dict];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
